<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>管理员登入</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="__LAYUIADMIN__/res/layui/css/layui.css" rel="stylesheet">
  <link href="__LAYUIADMIN__/res/adminui/dist/css/admin.css" rel="stylesheet">
  <link href="__LAYUIADMIN__/res/adminui/dist/css/login.css" rel="stylesheet">
  <style>
    .vercode {
      max-height: 38px;
      width: 100%;
      cursor: pointer;
      box-sizing: border-box;
    }
  </style>
</head>

<body>
  <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
      <div class="layadmin-user-login-box layadmin-user-login-header">
        <h2>管理员登入</h2>
        <p> </p>
      </div>
      <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
          <input type="text" name="qq" id="LAY-user-login-username" lay-verify="required" placeholder="QQ"
            class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
          <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码"
            class="layui-input">
        </div>
        <div class="layui-form-item">
          <div class="layui-row">
            <div class="layui-col-xs7">
              <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                for="LAY-user-login-vercode"></label>
              <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码"
                class="layui-input">
            </div>
            <div class="layui-col-xs5">
              <div style="margin-left: 10px;">
                <img src="{:captcha_src()}" alt="验证码" class="vercode">
              </div>
            </div>
          </div>
        </div>

        <div class="layui-form-item">
          <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
        </div>

      </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">

      <p>© All Rights Reserved by 怪鸟</p>

    </div>


  </div>

  <script src="__LAYUIADMIN__/res/layui/layui.js"></script>
  <script>
    layui.config({
      base: '__LAYUIADMIN__/res/' // 静态资源所在路径
    }).use(['index', 'user'], function () {
      var $ = layui.$
        , setter = layui.setter
        , admin = layui.admin
        , form = layui.form
        , layer = layui.layer
        , router = layui.router()
        , search = router.search;

      form.render();

      //提交
      form.on('submit(LAY-user-login-submit)', function (obj) {
        field = obj.field
        $.post('/admin/login', field, (res) => {
          if (res.code == 200) {
            layer.msg('登录成功')
            setTimeout(function () {
              window.location.href = '/admin'
            }, 2000)
          } else if (res.code == 230) {
            layer.msg('验证码错误')
            $('.vercode').attr('src', '/captcha.html?id=' + Math.random())
          } else {
            layer.msg(res.msg)
            $('.vercode').attr('src', '/captcha.html?id=' + Math.random())
          }
        })
        return false


      });
      $('.vercode').click(function(){
        $(this).attr('src' , '/captcha.html?id=' + Math.random())
      })
    });
  </script>
</body>

</html>